
package com.william.killian.trivia;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;

public class MainMenu extends ListActivity
{
    
    @Override
    public void onCreate (Bundle savedInstanceState)
    {
        super.onCreate (savedInstanceState);
        setTheme (android.R.style.Theme_Light);
        String[] menuItems = getResources ().getStringArray (R.array.menu);
        getListView ().setAdapter (new ArrayAdapter <String> (this, R.layout.menu_item, menuItems));
        getListView ().setOnItemClickListener (new Chooser ());
        getListView ().setScrollingCacheEnabled (false);
        getListView ().setDividerHeight (0);
    }

    private class Chooser implements OnItemClickListener
    {
        public void onItemClick (AdapterView <?> parent, View item, int pos, long id)
        {
            switch (pos)
            {
                case 0: // Play
                {
                    Intent intent = new Intent (MainMenu.this, ItemChooser.class);
                    intent.putExtra ("type", "quiz");
                    startActivity (intent);
                    break;
                }
                case 1: // Edit
                {
                    Intent intent = new Intent (MainMenu.this, ItemChooser.class);
                    intent.putExtra ("type", "edit");
                    startActivity (intent);
                    break;
                }
                case 2: // High Scores
                {
                    Intent intent = new Intent (MainMenu.this, ItemChooser.class);
                    intent.putExtra ("type", "hs");
                    startActivity (intent);
                    break;
                }
                case 3: // Help
                {
                    startActivity (new Intent (MainMenu.this, HelpViewer.class));
                    break;
                }
                case 4: // Quit
                {
                    finish ();
                    break;
                }
            }
        }
    }
}
